package com.swiftair.view
{
	import com.swiftair.ApplicationFacade;
	import com.swiftair.view.components.SettingsWindow;
	
	import flash.events.Event;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

    public class SettingsMediator extends Mediator implements IMediator
    {
        // Cannonical name of the Mediator
        public static const NAME:String = "SettingsMediator";

        public function SettingsMediator(viewComponent:SettingsWindow) {
            super(NAME, viewComponent);
			setupHandlers();
		}

        override public function listNotificationInterests():Array {
            return [];
        }

        override public function handleNotification(note:INotification):void {

        }

        protected function get settings():SettingsWindow {
            return viewComponent as SettingsWindow;
        }
		
		private function setupHandlers():void {
			settings.addEventListener(SettingsWindow.AUTHORIZE, onAuthorizeHandler);
			settings.addEventListener(SettingsWindow.GRANT, onGrantHandler);
		}
		
		private function onAuthorizeHandler(event:Event):void {
			sendNotification(ApplicationFacade.COMMAND_AUTHORIZE);
		}

		private function onGrantHandler(event:Event):void {
			sendNotification(ApplicationFacade.COMMAND_GRANT, settings.pin);
		}
    }
}